<template>
  <div class="companycard">
    <div class="companycard-title">
      <span>{{companyAndDep.type === "公司" ? "公司" : "部门"}}: </span>
      <span>{{companyAndDep.name}}</span>
    </div>
    <div class="companycard-message">
        <!-- 要判断 -->
      <div v-if="companyAndDep.type === '公司' && companyAndDep.district">
        <span>区域：</span>
        <span>{{companyAndDep.district}}</span>
      </div>
        <!-- 要判断 -->
      <div v-if="companyAndDep.type === '部门'">
        <span>归属：</span>
        <span>{{companyAndDep.ascription}}</span>
      </div>
      <div>
        <span>负责人：</span>
        <span>{{companyAndDep.leader ? companyAndDep.leader : "无" }}</span>
      </div>
      <div>
        <span>人数：</span>
        <span>{{companyAndDep.members}}</span>
      </div>
      <div v-if="companyAndDep.type === '公司'">
        <span>建立：</span>
        <span>{{ getDate(companyAndDep.estableDate) }}</span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "CompanyCard",
  props:{
    companyAndDep: Object
  },
  methods:{
    getDate(date) {
      //时间
      let newDate = new Date(date);
      let [year, month, day] = [
        newDate.getFullYear(),
        newDate.getMonth() + 1,
        newDate.getDate(),
      ];
      return `${year}-${month}-${day}`;
    },
  }
}
</script>

<style lang="scss">
  .companycard{
    box-sizing: border-box;
    // border: 1px solid red;
    height: inherit;
    width: inherit;
    padding: 8px 10px 6px 15px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: space-around;
    text-align: left;
    font-size: 14px;
    line-height: 1.8em;
    border-radius: 8px;

    &-title{
      font-size: 16px;
      font-weight: 700;
    }
    &-message{
      display: flex;
      flex-wrap: wrap;
      justify-content: flex-start;
      >div{
        white-space: nowrap;
        min-width: 50%;
      }
    }
  }
</style>